package com.tekj.cxqcb.view.Module.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.resultBean.selectAllBrandBean;

import java.util.List;


public class BrandAdapter extends BaseQuickAdapter<selectAllBrandBean.DataBean.BrandListBean, BaseViewHolder> {

    public BrandAdapter(@Nullable List<selectAllBrandBean.DataBean.BrandListBean> data) {
        super(R.layout.item_report, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, selectAllBrandBean.DataBean.BrandListBean item) {
        TextView tvName = helper.getView(R.id.tv_title);
        ImageView imgLogo = helper.getView(R.id.img_logo);
        imgLogo.setVisibility(View.VISIBLE);
        if (item.getImage() != null && !item.getImage().equals(""))
            Picasso.get().load(item.getImage())
                    .into(imgLogo);
        tvName.setText(item.getName());

    }

    /**
     * 提供给Activity刷新数据
     *
     * @param list
     */
    public void updateList(List<selectAllBrandBean.DataBean.BrandListBean> list) {
        this.mData = list;
        notifyDataSetChanged();
    }

    /**
     * 根据ListView的当前位置获取分类的首字母的char ascii值
     */
    public int getSectionForPosition(int position) {
        return mData.get(position).getLetters().charAt(0);
    }

    /**
     * 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置
     */
    public int getPositionForSection(int section) {
        for (int i = 0; i < getItemCount(); i++) {
            String sortStr = mData.get(i).getLetters();
            char firstChar = sortStr.toUpperCase().charAt(0);
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }

}
